package com.miracle.main.module.mvp.presenter;

import android.app.Activity;

import com.miracle.basemvp.base.BasePresenter;
import com.miracle.basemvp.base.BaseResponse;
import com.miracle.basemvp.base.IPresenter;
import com.miracle.basemvp.lifecycle.rx.RxDefaultObserver;
import com.miracle.common.mvp.entity.response.BaseListResponse;
import com.miracle.common.util.CommonConstants;
import com.miracle.common.util.PreferencesUtils;
import com.miracle.main.module.mvp.contract.AddSecretContract;
import com.miracle.main.module.mvp.entity.bean.FileItem;
import com.miracle.main.module.mvp.entity.request.AddSecretRequest;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.trello.rxlifecycle2.android.FragmentEvent;

import javax.inject.Inject;

/**
 * com.miracle.main.module.mvp.presenter
 * (c)2018 AIR Times Inc. All rights reserved.
 *
 *
 * @author WangJQ
 * @version 1.0
 * @date 2018/7/7 11:25
 * @see com.miracle.main.module.mvp.presenter
 */
public class AddSecretPresenter extends BasePresenter<AddSecretContract.View, AddSecretContract
        .Model> implements IPresenter {

    @Inject
    public AddSecretPresenter(AddSecretContract.View view, AddSecretContract.Model model) {
        super(view, model);
    }

    public void addSecret(LifecycleProvider<ActivityEvent> lifecycleProvider, AddSecretRequest
            request) {
        request.setUri(CommonConstants.URI.URI_ADD_SECRET);
        request.setJSESSIONID(PreferencesUtils.getPreferences((Activity)mView,PreferencesUtils.State.USER_SESSIONID));
        mModel.addSecret(request)
                .compose(lifecycleProvider.<BaseResponse<String>>bindUntilEvent
                        (ActivityEvent.DESTROY))
                .subscribe(new RxDefaultObserver<BaseResponse<String>>((Activity)mView) {

                    @Override
                    public void onSucceed(BaseResponse<String> stringBaseResponse) {
                        mView.addSucc();
                    }

                });
    }
}
